$(document).ready(function(){

	access_token = getQueryString(window.location.href,"access_token");
	if(access_token == null){
		access_token = $.getCookie("access_token");
	}
	var sortTime = "";

	$.loadMessage = function(){
		$.getJSON("/"+server+"/ticketGet?access_token="+access_token+"&sortTime="+sortTime,function(json){
			sortTime = json.sortTime;
			if(json.result == 1){
					for(var i=0;i<json.data.length;i++){
						// if(json.data[i].ticketType == 1){
							var ticketStr = "";
							if(json.data[i].type.discount == 0){
								ticketStr = "免费购线券";
							}
							else{
								ticketStr = parseInt(json.data[i].type.discount*10)+"折购线券";	
							}


							$("body").append(	
								'<div class="ticket">'+
									'<img class="ticket-top" src="/static/images/ticket-top.png">'+
									'<p>'+
										'<span class="name">'+ticketStr+'</span>'+
										'<br/>'+
										'<span class="addTime">获取时间：'+json.data[i].addTime+'</span>'+
									'</p>'+
									'<span class="describe">不可充当押金使用</span>'+
									'<img class="ticket-bottom" src="/static/images/ticket-bottom.png">'+
								'</div>'
							)
						// }
					}			
			}
			if(sortTime == -1){
				$("body").append(
					'<div class="no-data" style="text-align:center;font-size:1em">'+
						'没有更多优惠券了！'+
					'</div>'
				)
			}
		})
	}

	$.loadMessage();

	$(window).scroll(function() {
		if(sortTime != -1){
			if($(document).scrollTop() + $(window).height() >= $(document).height()){
				$('.loading-more').show();
				$.loadMessage();
			}
		}
	});		

})